package com.liuqi09.mapper;

import com.liuqi09.po.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

/**
 * @author LiuQi
 * @create 2025-10-20-16:41
 */
@Mapper
public interface UserMapper {

    @Insert("insert into users(username,password,email) values(#{username},#{password},#{email})")
    public int addUser(User user);

    @Delete("delete from users where id=#{id}")
    public int deleteUser(Integer id);

    @Update("update users set username=#{username},password=#{password},email=#{email} where id=#{id}")
    public int updateUser(User user);

    @Select("select * from users where id=#{id}")
    public User queryUserById(Integer id);

    //查询用户的并查询所有歌单
    @Select("select * from users where id= #{id}")
    @Results(id = "userMap",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "email",property = "email"),
            @Result(column = "id",property = "playlists",
                    many = @Many(select = "com.liuqi09.mapper.PlaylistMapper.queryPlaylistByUserId",
                            fetchType = FetchType.LAZY))
    })
    public User queryUserByIdAndPlaylists(Integer id);
}
